﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Program11
{
    class Program
    {
        public enum QQState
        {
            //枚举的成员可以定义它们的整型值
            online=1,
            offline=0,
            leave=2,
            busy=3,
            QQme=4
        }
        static void Main(string[] args)
        {
            #region 枚举类型转换成int
            QQState state = QQState.online;
            int i = (int)state;
            Console.WriteLine("QQ在线枚举成员的值：" + i);
            Console.WriteLine("QQ离线枚举成员的值：" + (int)QQState.offline);
            #endregion

            #region 将int转换成枚举类型
            int n = 0;
            Console.WriteLine("QQ在线枚举成员的值：" + (QQState)n);
            #endregion

            #region 将字符串转换成枚举类型
            string str = "leave";
            //将字符串“leave”转换成 QQState.leave
            //字符串类型转换成枚举类型语法
            QQState state1 = (QQState)Enum.Parse(typeof(QQState), str);
            Console.WriteLine(state1);
            Console.WriteLine((int)state1);
            #endregion

            Console.ReadLine();
        }
    }
}
